#include "logger/Logger.h"
#include "logger/Appender.h"

Logger::Logger ():
	level (LOG_DEBUG), appender (0){};

void Logger::setAppender (Appender * appender) {
	this->appender = appender;
};

void Logger::setLevel (int level) {
	this->level = level;
};

void Logger::log (int level, String message, ...) {
	checkState ();
	if (this->level >= level)
		appender->log(level, message);
};

void Logger::checkState () {
	//TODO should we use normal exceptions here and get a stack traces?
	//see http://www.ibm.com/developerworks/linux/library/l-cppexcep.html
	if (appender == 0) throw "No appender set for the logger";
};

void Logger::info (String message) {
	log(LOG_INFO, message);
};

void Logger::warn (String message) {
	log(LOG_WARN, message);
};

void Logger::debug (String message) {
	log(LOG_DEBUG, message);
};

void Logger::error (String message) {
	log(LOG_ERROR, message);
};
